from PyQt5.QtWidgets import (
    QDialog, QVBoxLayout, QCheckBox, QLineEdit, QLabel,
    QHBoxLayout, QDialogButtonBox
)

class CacheCleanDialog(QDialog):
    """缓存清理对话框"""

    def __init__(self, parent=None):
        super().__init__(parent)
        self.setWindowTitle("清理缓存")
        self.resize(400, 200)

        layout = QVBoxLayout()

        # 缓存选项
        self.chk_older = QCheckBox("清理超过指定天数的缓存")
        self.chk_older.setChecked(True)
        self.days_edit = QLineEdit("30")
        self.days_edit.setFixedWidth(50)

        days_layout = QHBoxLayout()
        days_layout.addWidget(self.chk_older)
        days_layout.addWidget(QLabel("天数:"))
        days_layout.addWidget(self.days_edit)
        days_layout.addStretch()

        self.chk_unused = QCheckBox("清理超过指定天数未使用的缓存")
        self.chk_unused.setChecked(True)
        self.unused_days_edit = QLineEdit("90")
        self.unused_days_edit.setFixedWidth(50)

        unused_layout = QHBoxLayout()
        unused_layout.addWidget(self.chk_unused)
        unused_layout.addWidget(QLabel("天数:"))
        unused_layout.addWidget(self.unused_days_edit)
        unused_layout.addStretch()

        # 按钮
        button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
        button_box.accepted.connect(self.accept)
        button_box.rejected.connect(self.reject)

        layout.addLayout(days_layout)
        layout.addLayout(unused_layout)
        layout.addWidget(button_box)

        self.setLayout(layout)

    def get_settings(self):
        """获取清理设置"""
        return {
            'clean_older': self.chk_older.isChecked(),
            'days': int(self.days_edit.text()),
            'clean_unused': self.chk_unused.isChecked(),
            'unused_days': int(self.unused_days_edit.text())
        }